
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Scanner;
import java.text.DateFormat;
import java.text.SimpleDateFormat;



public class MakeLog {
	public static void makeLog(String[] args) throws IOException {
		File log = new File("C:\\files\\log.txt");
		if(log.exists()){
			System.out.println("File not created!");
			if(log.canWrite()){
				FileWriter fileWriter = new FileWriter(log,true); 
				PrintWriter printWriter = new PrintWriter(fileWriter);
				printWriter.println((getDate()));
				fileWriter.close();
				printWriter.close();
				}
		}else {
			try {
				log.createNewFile();
				System.out.println("File created OK!");
			} catch (IOException e) {
				System.out.println("couldn't create a new file!");
				e.printStackTrace();
			}
		}
		printFile();

	}
	public static String getDate() {

		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		Date date = new Date();
		return dateFormat.format(date);
		//get date with calendar
		//Calendar cal = Calendar.getInstance();
		//System.out.println(dateFormat.format(cal.getTime()));
	}
	public static void printFile() throws IOException {
		File file = new File("c:\\files\\log.txt");
		Scanner readFile = new Scanner(file);
		if(file.exists()&&file.canRead()){
			while(readFile.hasNext()){
				System.out.println(readFile.nextLine());
			}
		}
			
	}
}
